// MCP Server Base Class
// MCP服务器基类
class MCPServer {
  constructor(name, port) {
    this.name = name;
    this.port = port;
    this.connectedClients = new Set();
    this.dataSources = new Map();
  }

  // Register a data source
  // 注册数据源
  registerDataSource(name, dataSource) {
    this.dataSources.set(name, dataSource);
  }

  // Get data from a specific source
  // 从指定数据源获取数据
  getData(sourceName) {
    const source = this.dataSources.get(sourceName);
    if (source) {
      return source.getData();
    }
    return null;
  }

  // Send command to a data source
  // 向数据源发送命令
  sendCommand(sourceName, command) {
    const source = this.dataSources.get(sourceName);
    if (source) {
      return source.executeCommand(command);
    }
    return false;
  }

  // Start the MCP server
  // 启动MCP服务器
  start() {
    console.log(`${this.name} MCP Server started on port ${this.port}`);
  }

  // Stop the MCP server
  // 停止MCP服务器
  stop() {
    console.log(`${this.name} MCP Server stopped`);
  }
}

module.exports = MCPServer;